package com.biscuit.page.basicservice.utils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author mazihao
 * @createTime 2024/3/29 13:33
 */
public class DateUtil {

    public static String getCurrentDateTime() {
        return cn.hutool.core.date.DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss");
    }

    public static String getCurrentDate() {
        return cn.hutool.core.date.DateUtil.format(new Date(), "yyyy-MM-dd");
    }

    public static String format(Date date, String patter) {
        return cn.hutool.core.date.DateUtil.format(new Date(), patter);
    }

    public static LocalDateTime getLocalDateTime(String datetime) {
        return getLocalDatetime(datetime, "yyyy-MM-dd HH:mm:ss");
    }

    public static LocalDate getLocalDate(String date) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        return LocalDate.parse(date, formatter);
    }

    public static LocalDateTime getLocalDatetime(String datetime, String pattern) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
        return LocalDateTime.parse(datetime, formatter);
    }

}
